﻿@{
    ViewData["Title"] = "HouseAdd";
    Layout = null;
}
<html>
<head>
    <link href="~/layui/css/layui.css" rel="stylesheet" />
    <script src="~/layui/layui.js"></script>
    <script src="~/libs/jquery/jquery.js"></script>
</head>
<body>

    <form class="layui-form layui-form-pane" action="">
        <div class="layui-row">
            <div class="layui-col-xs6">
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 100px;">仓库编码</label>
                    <div class="layui-input-block">
                        <input type="text" name="WarehouseCode" id="WarehouseCode" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
                        <button class="layui-btn layui-btn-normal" id="test-btn-other">随机生成</button>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 100px;">仓库名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="WarehouseName" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 100px;">仓库面积</label>
                    <div class="layui-input-block">
                        <input type="text" name="Area" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 100px;">负责人</label>
                    <div class="layui-input-block">
                        <input type="text" name="Charge" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
                    </div>
                </div>
            </div>

            <div class="layui-col-xs6">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label" style="width: 100px;">仓库位置</label>
                    <div class="layui-input-block">
                        <textarea name="Location" placeholder="请输入内容" class="layui-textarea"></textarea>
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label" style="width: 100px;">备注</label>
                    <div class="layui-input-block">
                        <textarea name="Remark" placeholder="请输入内容" class="layui-textarea"></textarea>
                    </div>
                </div>

               
            </div>

            <div class="layui-form-item" style="text-align: center;">
                <div class="layui-input-block">
                    <button class="layui-btn" type="button" lay-submit lay-filter="addHouse">确认</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
            
        </div>
    </form>


    <script>
        layui.use(['form', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
            $ = layui.$;

            // 提交事件
            form.on('submit(addHouse)', function (data) {
                data = data.field;

                $.get("/QiData/AddWareHouse", data,
                    res => {
                        console.log(res);
                        if (res) {
                            console.log(res);
                            layer.msg('添加成功', {
                                icon: 1,
                                time: 1000
                            }, function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                //cation.href = '/QiData/HouseShow';
                                window.location = '/QiData/HouseShow';
                            });
                        }
                        else {
                            layer.msg('添加失败！', {
                                icon: 1,
                                time: 1000
                            });
                        }
                    }
                )


            });

            $('#test-btn-other').on('click', function () {
                var index = "1234567890";
                var num = "";
                for (var i = 0; i < 5; i++) { // 循环10次
                    // 生成一个五位数的随机数
                    var randomFiveDigitNumber = Math.floor(Math.random() * index.length);
                    num += index[randomFiveDigitNumber]
                }
                var codes ="B"+ "C" + num;
                $("[name=WarehouseCode]").val(codes);
                return false;
            });
        });

    </script>

</body>

</html>
